package com.example.mine

import android.os.Bundle
import android.view.View
import androidx.databinding.ViewDataBinding
import com.example.common.base.BaseFragment
import com.example.mine.databinding.FragmentMineBinding
import com.example.servcie.repo.DbHelper
import org.koin.androidx.viewmodel.ext.android.viewModel

/*
* 我的 Fragment
* 传入了R.layout.fragment_course之后就不用写onCreateView,因为布局已经被关联到fragment里了
* */
class MineFragment : BaseFragment() {

    private val viewModel: MineViewModel by viewModel()

    //传入布局资源,将布局和view绑定到一起
    override fun getLayoutRes() = R.layout.fragment_mine

    //传入view,将view和databinding绑定到一起
    override fun bindView(view: View, savedInstanceState: Bundle?): ViewDataBinding {
        return FragmentMineBinding.bind(view).apply {
            vm = viewModel
        }
    }

    override fun initData() {
        super.initData()
        //requireContext 返回此片段的上下文
        DbHelper.getLiveUserInfo(requireContext()).observeKt {
            //观察登录后的数据
            viewModel.liveUser.value = it
        }
    }
}